class Node {
  constructor(value = null, next = null) {
    this.value = value // 元素
    this.next = next // 指向另一条链表，另一个结点的值
  }
}
let first = new Node('1')
const second = new Node('2')
const third = new Node('3')
first.next = second
second.next = third
console.log(JSON.stringify(first, null, 2))

// 表头插入
function insertNodeAtHead (link, node) {
  node.next = link
  return node
}
const insert = new Node('0', null)
first = insertNodeAtHead(first, insert)
console.log(JSON.stringify(first, null, 2))
// 表头删除
function deleteNodeAtHead (link) {
  link.value = null
  return link.next
}
first = deleteNodeAtHead(first)
console.log(JSON.stringify(first, null, 2))
// 表尾插入
// function insertNodeInTail(link, node) {
//   let p = link;
//   while (p.next !== null) {
//     p = p.next;
//   }
//   p.next = node;
// }
// const insert = new Node('4');
// insertNodeInTail(first, insert);
// console.log(JSON.stringify(first, null, 2));

